//
// Created by afly on 20-12-28.
// Mail: a_fly0505@163.com
// QQ: 785230837 WX: afly003
// Company: juefx
//
//
#include <iostream>
#include "thread_qsm.h"

namespace qsm {

    int Thread::m_sThreadIndex = 0;

    int32_t Thread::SetSetafftinityNp() {
        int cpu_id = m_sThreadIndex % std::thread::hardware_concurrency();
        cpu_set_t cpuset;
        CPU_ZERO(&cpuset);
        CPU_SET(cpu_id, &cpuset);
        int rc = pthread_setaffinity_np(this->native_handle(), sizeof(cpu_set_t), &cpuset);
        if (rc != 0) {
            std::cout << "Error calling pthread_setaffinity_np= " << rc;
            return -1;
        }
        m_sThreadIndex++;
        return 0;
    }
}
